home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Programmer Disk
/
The Programmer Disk (Microforum).iso
/
xpro
/
qb1
/
pro2
/
keyboard.bas
< prev
next >
Wrap
BASIC Source File
|
1992-03-21
|
10KB
|
236 lines
DEFINT A-Z
'+==================================================================+
'| KEYBOARD.BAS |
'| |
'| A set of input routines developed by Larry Stone and the SWOCC |
'| students of Larry Stone, CS133B, Fall Term '91, SWOCC. |
'+------------------------------------------------------------------+
'
DECLARE FUNCTION InsertState% ()
DECLARE FUNCTION KeyPressed% ()
DECLARE FUNCTION Lower% (Value%)
DECLARE FUNCTION Upper% (Value%)
CONST True = -1
CONST False = 0
'+==================================================================+
'| SUBPROGRAMS |
'+------------------------------------------------------------------+
FUNCTION InsertState%
'---- Insert is either On or Off and InsertState% is set to True or False
DEF SEG = False 'Go to ROM segment
InsertState% = (PEEK(&H417) AND 128) = 128 '1000 0000
DEF SEG 'Back to BASIC DGROUP
END FUNCTION
'+==============================================================+
'| KeyPressed% FUNCTION |
'| |
'| Input: Nothing |
'| Return: The function returns an integer representing the |
'| ASCII value of a keystroke. If an extended key |
'| value is returned from the keyboard buffer then the |
'| right byte (scan code) is returned as a negative |
'| value. If no keystroke is pending in the keyboard |
'| buffer then zero is returned. |
'+--------------------------------------------------------------+
FUNCTION KeyPressed%
Temp$ = INKEY$ 'Get a keystroke from the keyboard buffer
IF LEN(Temp$) THEN 'If we got a key from the buffer
'---- Set value representing the right byte
AsciiValue = ASC(RIGHT$(Temp$, 1))
'---- If extended key value then flag it so by changing its sign
IF LEN(Temp$) = 2 THEN AsciiValue = -AsciiValue
ELSE 'No key value found in keyboard buffer
AsciiValue = False 'So, set value to zero
END IF
KeyPressed = AsciiValue 'Set the function to value derived
END FUNCTION
'+==============================================================+
'| Lower% FUNCTION |
'| |
'| Input: An INTEGER value. |
'| Return: The function returns the integer, unaltered, if |
'| the value of the INTEGER is outside of the lower |
'| case letter range. If the INTEGER is between 65 |
'| and 90 (ASCII for 'A' through 'Z') then 32 is ORed |
'| (added), resulting in a return value of 97 through |
'| 122 (ASCII for 'a' through 'z'). |
'+--------------------------------------------------------------+
FUNCTION Lower% (Value%)
IF Value > 64 AND Value < 91 THEN Lower = Value OR 32 ELSE Lower = Value
END FUNCTION
'+==============================================================+
'| RingSound SUBPROGRAM |
'| |
'| Input: Nothing |
'| Return: Nothing |
'| Purpose: Produces a more pleasing sound than BEEP. |
'| Does not use floating point library. |
'| |
'+--------------------------------------------------------------+
SUB RingSound
OUT &H43, 182 ' set up for sound
OUT &H42, &H33 ' low part of sound
OUT &H42, 5 ' high part of sound
N = INP(&H61) ' get byte value from port
N1 = N ' save value as N1
N = N OR 3 ' set bits 0 and 1 to o«
CLS
Frame.boxType = 2: Frame.filClr = 3 'Define the frame parameters
Frame.fore = 15: Frame.back = 1
Frame.lftCol = 1: Frame.rgtCol = 80
Frame.tRow = 1: Frame.bRow = 13
Box Frame 'Draw frame for input fields
Frame.back = 4: Frame.filClr = 4
Frame.tRow = 15: Frame.bRow = 19
Frame.boxType = 4: Box Frame 'Draw frame for edit help box
COLOR 1, 3 'Tell user what process is
LOCATE 3, 32
PRINT "Edit Data Routine"
LOCATE 11, 3: COLOR 4, 3 'Display brief help message
PRINT "Use: "; CHR$(24); " "; CHR$(25); " PgUp PgDn. <Enter> on last entry to process changes. <Esc>: Abort"
COLOR 15, 3 'Finish setting up the form
LOCATE 5, 3: PRINT "Last/First => ";
LOCATE , 37: PRINT ","
LOCATE 6, 3: PRINT "Address => "
LOCATE 7, 3: PRINT "Telephone => ( ) -";
LOCATE 8, 3: PRINT "Memo => "
LOCATE 9, 3: PRINT "Save To => "
COLOR 15, 4 'Messages inside of Help Box
LOCATE 16, 33: PRINT "Editor Commands"
LOCATE 17, 4
PRINT "Scroll line: ─"; CHR$(16); " "; CHR$(17); "─ <Home> <End> <Ctrl> + ─"; CHR$(16); " <Ctrl> + "; CHR$(17); "─"
LOCATE 18, 4
PRINT "Delete with: <Delete> <Backspace> <Ctrl> + <Home> <Ctrl> + <End>"
COLOR 15, 5
FOR N = 1 TO MaxChoice
LOCATE EditRow%(N), EditCol(N)
PRINT LEFT$(EditStrings$(N) + SPACE$(DisplaySize(N)), DisplaySize(N))
NEXT
RETURN
DefineEditorVariables:
'---- Initialize LineEdit's Terminators array. Terminators are
' REQUIRED by the editor. The zeroeth element of the array
' defines how many elements the editor will use.
Terminators(False) = 5 'Only using first 5 for right now
Terminators(1) = 27 'Terminate on Esc key
Terminators(2) = -72 'Terminate on Up arrow
Terminators(3) = -80 'Terminate on Down arrow
Terminators(4) = -73 'Terminate on Page Up
Terminators(5) = -81 'Terminate on Page Down
'---- These terminators are not used in this demo example. We've
' DIMmed Terminators (10) so 2 more can still be defined.
Terminators(6) = -132 'Terminate on Ctrl + Page Up
Terminators(7) = -118 'Terminate on Ctrl + Page Down
Terminators(8) = -68 'Terminate on F10 key
'---- Initialize LineEdit's word separater string
Separaters$ = " .:-(){}\/"
'---- Define some data. Note data could be retrieved from file or DATA
EditStrings$(1) = "Stone"
EditRow%(1) = 5
EditCol(1) = 17
WindSize(1) = False
DisplaySize(1) = 20
'---- "A*" + string "a"
EditMask$(1) = LEFT$("A*" + STRING$(DisplaySize(1), 97), DisplaySize(1))
EditStrings$(2) = "Lawrence"
EditRow%(2) = 5
EditCol(2) = 39
WindSize(2) = False
DisplaySize(2) = 20
'---- "A" + string "*"
EditMask$(2) = LEFT$("A" + STRING$(DisplaySize(2), 42), DisplaySize(2))
EditStrings$(3) = "1234"
EditRow%(3) = 6
EditCol(3) = 14
WindSize(3) = False
DisplaySize(3) = 9
EditMask$(3) = STRING$(DisplaySize(3), "8")
EditStrings$(4) = "Main Street"
EditRow%(4) = 6
EditCol(4) = 24
WindSize(4) = False
DisplaySize(4) = 35
EditStrings$(5) = "503"
EditRow%(5) = 7
EditCol(5) = 17
WindSize(5) = False
DisplaySize(5) = 3
EditMask$(5) = STRING$(DisplaySize(5), "9")
EditStrings$(6) = "756"
EditRow%(6) = 7
EditCol(6) = 21
WindSize(6) = False
DisplaySize(6) = 3
EditMask$(6) = STRING$(DisplaySize(6), "9")
EditStrings$(7) = "5935"
EditRow%(7) = 7
EditCol(7) = 25
WindSize(7) = False
DisplaySize(7) = 4
EditMask$(7) = STRING$(DisplaySize(7), "9")
EditStrings$(8) = "Now is the time for all good men to come to the aid of their "
EditStrings$(8) = EditStrings$(8) + "fellow countrymen. In the land of the blind, the one-"
EditStrings$(8) = EditStrings$(8) + "eyed man is king. Good QB programmers always respond "
EditStrings$(8) = EditStrings$(8) + "to a challange and, in so doing, become better programmers."
EditRow%(8) = 8
EditCol(8) = 11
WindSize(8) = 300
DisplaySize(8) = 67
EditStrings$(9) = "C:\BASIC\STUFF\PERSONAL.DAT"
EditRow%(9) = 9
EditCol(9) = 14
WindSize(9) = False
DisplaySize(9) = 64
RETURN
'+==================================================================+
'| SUBPROGRAMS |
'+------------------------------------------------------------------+
&HB809
INTERRUPT &H2F, Registers, Registers
Major% = Registers.ax \ 256 ' AH
Minor% = Registers.ax - (Major * 256) ' AL
END SUB
SUB Redirect (DevType%, DevName$, NetPath$) ' Redirect a device
'ND Value < 123 THEN Upper = Value AND 223 ELSE Upper = Value
END FUNCTION